package com.zretc.controller;

import com.util.Result;
import com.zretc.pojo.FamilyInfo;
import com.zretc.service.FamilyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@Api("家庭信息模块")
@ApiOperation("FamilyController")
public class FamilyController {
    @Autowired
    public FamilyService familyService;

    @ApiOperation(value ="查询家庭信息")
    @GetMapping("/selectId")
    public Result<List<FamilyInfo>> selectId(@RequestParam("idNumber")String idCard){
        List<FamilyInfo> familyInfo = familyService.getFamilyInfo(idCard);
        return Result.success(familyInfo);
    }

    @ApiOperation(value ="添加家庭信息")
    @PostMapping("/addFamilyInfo")
    public Result addFamilyInfo(@RequestBody FamilyInfo familyInfo){
        System.out.println(familyInfo);
        Integer result = familyService.addFamilyInfo(familyInfo);
        System.out.println(result);
        if(result == 1){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
        return Result.success(result);
    }

    @ApiOperation(value ="查询某家庭成员信息")
    @GetMapping("/selectIdFamilyInfo")
    public Result selectIdFamilyInfo(@RequestParam("familyId")Integer familyId){
        FamilyInfo familyInfo = familyService.selectIdFamilyInfo(familyId);
        System.out.println(familyInfo);
        return Result.success(familyInfo);
    }


    @ApiOperation(value ="更改家庭信息")
    @PostMapping("/editFamilyInfo")
    public Result editFamilyInfo(@RequestBody FamilyInfo familyInfo){
        System.out.println(familyInfo);
        Integer result = familyService.editFamilyInfo(familyInfo);
        return Result.success(result);
    }


    @ApiOperation(value ="删除家庭信息")
    @GetMapping("/deleteFamilyInfo")
    public Result deleteFamilyInfo(@RequestParam("familyId")Integer familyId){
        Integer result = familyService.deleteFamilyInfo(familyId);
        if(result == 1){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
        return Result.success(result);
    }



}
